#
# global platform config.mk prior to the local configuration
#
include $(WORKDIR)/config.mk

# appointed libs and their dir
LOCAL_SHARED_LIB := akuio akmedia akaudiocodec akaudiofilter akstreamenc \
					akispsdk

# decide locate what kind of lib
ifeq ($(COMPILE_SO), y)
LOCAL_SHARED_LIB += plat_common plat_thread plat_vi \
					plat_vpss plat_drv plat_ai plat_ao plat_its \
					mpi_adec mpi_aenc mpi_venc mpi_muxer mpi_osd mpi_md \
					app_dvr app_net app_ini
PLAT_STATIC_LIB :=
MPI_STATIC_LIB :=
APP_STATIC_LIB :=
else
PLAT_STATIC_LIB := plat_common plat_thread plat_vi plat_vpss plat_drv
PLAT_STATIC_LIB += plat_ai plat_ao plat_its
MPI_STATIC_LIB := mpi_adec mpi_aenc mpi_venc mpi_muxer mpi_osd mpi_md
APP_STATIC_LIB := app_ini app_dvr app_net
endif

# support RTSP
ifeq ($(COMPILE_SO), y)
	RTSP_STATIC_LIB :=
	LOCAL_SHARED_LIB += akliveMedia BasicUsageEnvironment groupsock \
		liveMedia UsageEnvironment cloud_rtsp
else
	APP_STATIC_LIB += cloud_rtsp
	RTSP_STATIC_LIB := akliveMedia BasicUsageEnvironment groupsock \
		liveMedia UsageEnvironment
endif

# appointed link lib
LIBS := $(addprefix $(PLAT_LIB_DIR)/,$(patsubst %,lib%.a,$(PLAT_STATIC_LIB)))
LIBS += $(addprefix $(MPI_LIB_DIR)/,$(patsubst %,lib%.a,$(MPI_STATIC_LIB)))
LIBS += $(addprefix $(APP_LIB_DIR)/,$(patsubst %,lib%.a,$(APP_STATIC_LIB)))
ifeq ($(COMPILE_SO), n)
	LIBS += $(addprefix $(RTSP_LIB_DIR)/,$(patsubst %,lib%.a,$(RTSP_STATIC_LIB)))
endif

LOCAL_LDFLAGS := -L$(PLAT_LIB_DIR) -L$(MPI_LIB_DIR) -L$(APP_LIB_DIR)

# support RTSP
ifeq ($(COMPILE_SO), y)
	LOCAL_LDFLAGS += -L$(RTSP_SHARED_LIB_DIR)
else
	LOCAL_LDFLAGS += -L$(RTSP_LIB_DIR)
endif

LDFLAGS := $(LOCAL_LDFLAGS)

LDFLAGS += $(addprefix -l,$(patsubst lib%,%,$(LOCAL_SHARED_LIB)))
LDFLAGS += $(STD_LDFLAGS)

OBJS := $(wildcard *.o)
LD := $(CROSS_COMPILE)g++
TARGET := product_test

all: $(TARGET)

$(TARGET): $(OBJS)
	$(LD) $^ $(LDFLAGS) -Xlinker "-(" $(LIBS) -Xlinker "-)" -o $@
	$(RM) *.o
ifeq ($(DEBUG), n)
	$(STRIP) $@
endif

install:
	@$(CP) $(TARGET) $(ROOTFS_BIN_DIR)

clean:
	$(RM) *.o
	$(RM) $(TARGET)

.PHONY: all install clean
